using Abc.Application;

using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;

using System.Threading.Tasks;

namespace Abc.Web.Mvc.Areas.HtAdmin.Controllers
{
    [NonValidation]
    //[AuthorizePolicy]
    [AllowAnonymous]
    public class NotepadController : HtAdminBaseController
    {
        private readonly ILogger<NotepadController> _logger;
        private readonly INotepadService _notepadService;

        public NotepadController(ILogger<NotepadController> logger
        , INotepadService notepadService)
        {
            _logger = logger;
            _notepadService = notepadService;
        }

        [HttpGet]
        public async Task<IActionResult> Index()
        {
            return View();
        }

        [HttpGet, HttpPost]
        public async Task<JsonResult> GetList(NotepadQuery searchquery)
        {
            var pagedlist = await _notepadService.GetAllByPageToLayui(searchquery);
            return Json(pagedlist);
        }

        public async Task<ActionResult> Info(int? id)
        {
            NotepadOut entity = null;
            if (id.HasValue)
            {
                entity = await _notepadService.Find(id.Value);
            }
            return View(entity ?? new NotepadOut());
        }

        [HttpPost]
        // [ValidateInput(false)]
        public async Task<JsonResult> Info(NotepadInput input)
        {
            return Json(await _notepadService.InsertOrUpdate(input));
        }

        [HttpPost]
        public async Task<ActionResult> Delete(int id)
        {
            return Json(await _notepadService.Delete(id));
        }

        //[HttpPost]
        //public async Task<JsonResult> SetState(int id, bool state, string type)
        //{
        //    var resultdata = await _notepadService.SetState(id, state, type);
        //    return Json(resultdata);
        //}
    }
}